package com.turnengine.client.global.game.command;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Get Game Instance By Names.
 */
public class GetGameInstanceByNames implements IGetGameInstanceByNames {

	/** The command id. */
	public static final short COMMAND_ID = 319;

	/** The game name. */
	private String gameName;
	/** The version name. */
	private String versionName;
	/** The instance name. */
	private String instanceName;

	/**
	 * Creates a new Get Game Instance By Names.
	 */
	public GetGameInstanceByNames() {
	}

	/**
	 * Creates a new Get Game Instance By Names.
	 * @param gameName the game name
	 * @param versionName the version name
	 * @param instanceName the instance name
	 */
	public GetGameInstanceByNames(String gameName, String versionName, String instanceName) {
		setGameName(gameName);
		setVersionName(versionName);
		setInstanceName(instanceName);
	}

	/**
	 * Creates a new Get Game Instance By Names.
	 * @param iGetGameInstanceByNames the i get game instance by names
	 */
	public GetGameInstanceByNames(IGetGameInstanceByNames iGetGameInstanceByNames) {
		setGameName(iGetGameInstanceByNames.getGameName());
		setVersionName(iGetGameInstanceByNames.getVersionName());
		setInstanceName(iGetGameInstanceByNames.getInstanceName());
	}

	/**
	 * Returns the game name.
	 * @return the game name.
	 */
	public String getGameName() {
		return gameName;
	}

	/**
	 * Returns the version name.
	 * @return the version name.
	 */
	public String getVersionName() {
		return versionName;
	}

	/**
	 * Returns the instance name.
	 * @return the instance name.
	 */
	public String getInstanceName() {
		return instanceName;
	}

	/**
	 * Sets the game name.
	 * @param gameName the game name to set.
	 */
	public void setGameName(String gameName) {
		if (gameName == null) {
			throw new NullPointerException("gameName");
		}
		this.gameName = gameName;
	}

	/**
	 * Sets the version name.
	 * @param versionName the version name to set.
	 */
	public void setVersionName(String versionName) {
		if (versionName == null) {
			throw new NullPointerException("versionName");
		}
		this.versionName = versionName;
	}

	/**
	 * Sets the instance name.
	 * @param instanceName the instance name to set.
	 */
	public void setInstanceName(String instanceName) {
		if (instanceName == null) {
			throw new NullPointerException("instanceName");
		}
		this.instanceName = instanceName;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(139, 37);
		hash.append(gameName);
		hash.append(versionName);
		hash.append(instanceName);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof GetGameInstanceByNames) {
			GetGameInstanceByNames compare = (GetGameInstanceByNames) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.gameName, compare.gameName);
			equals.append(this.versionName, compare.versionName);
			equals.append(this.instanceName, compare.instanceName);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IGetGameInstanceByNames compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.gameName, compare.getGameName());
		builder.append(this.versionName, compare.getVersionName());
		builder.append(this.instanceName, compare.getInstanceName());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		if (gameName != null) {
			string.append("gameName", gameName);
		}
		if (versionName != null) {
			string.append("versionName", versionName);
		}
		if (instanceName != null) {
			string.append("instanceName", instanceName);
		}
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
